//
//  FirstViewController.m
//  Qihuo
//
//  Created by Vencoo on 13-9-25.
//  Copyright (c) 2013年 Vencoo. All rights reserved.
//
#import "ViewController.h"
#import "FirstViewController.h"
#import "MeetingViewController.h"
#import "MaterialViewController.h"
#import "NewsViewController.h"
#import "UIButton+MyButton.h"
#import "secureXJViewController.h"
#import "ProjectCJViewController.h"
#import "FunctionXJViewController.h"
#import "CheckViewController.h"
#import "EmergencyViewController.h"
#import "BaoXiuJiLuViewController.h"
#import "PerSonOrganizerViewController.h"
#import "AnalysisViewController.h"
@interface FirstViewController ()
{
    UIImageView *blackView;
}
@end

@implementation FirstViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = @"首页";
    [self.navigationController.navigationBar setBarStyle:UIBarStyleBlackTranslucent];
    UIImage *backgroundImage = [UIImage imageNamed:@"底111"];
    UIImageView *backgroundView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, backgroundImage.size.width, 768)];
    [backgroundView setImage:backgroundImage];
    [self.view addSubview:backgroundView];
    
    UIImage *image = [UIImage imageNamed:@"注销"];
    UIButton* btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(60, (44-image.size.height)/2, image.size.width, image.size.height);
    [btn setBackgroundImage:image forState:UIControlStateNormal];
    [btn addTarget:self.navigationController action:@selector(dismissModalViewControllerAnimated:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* backBtn = [[UIBarButtonItem alloc]initWithCustomView:btn];
    self.navigationItem.rightBarButtonItem = backBtn;
    
    UILabel *welcomeLB = [UILabel new];
    welcomeLB.text = [NSString stringWithFormat:@"欢迎您：%@",[self.delegate.DataDic valueForKey:@"username"]];
#pragma mark - test
//    welcomeLB.text = [NSString stringWithFormat:@"欢迎您：admin"];
    welcomeLB.font = [UIFont systemFontOfSize:30];
    welcomeLB.backgroundColor = [UIColor clearColor];
    welcomeLB.textColor = [UIColor whiteColor];
    CGSize mySize = [welcomeLB.text sizeWithFont:welcomeLB.font constrainedToSize:CGSizeMake(MAXFLOAT, 40)];
    welcomeLB.frame = CGRectMake(20, 77, mySize.width, mySize.height);
    [self.view addSubview:welcomeLB];
    
    UILabel *departmentLb = [UILabel new];
#pragma mark - test
    switch ([[self.delegate.DataDic valueForKey:@"departmentid"]intValue]) {
    
    
//            switch (self.delegate.testDepart) {
        case 1:
            departmentLb.text = @"部门：保安部";
            break;
        case 2:
            departmentLb.text = @"部门：工程部";
            break;
        case 3:
            departmentLb.text = @"部门：运作部";
            break;
            
        default:
            break;
    }
    departmentLb.backgroundColor = [UIColor clearColor];
    departmentLb.font = [UIFont systemFontOfSize:30];
    departmentLb.textColor = [UIColor whiteColor];
    mySize = [departmentLb.text sizeWithFont:departmentLb.font constrainedToSize:CGSizeMake(MAXFLOAT, 40)];
    departmentLb.frame = CGRectMake(475, welcomeLB.frame.origin.y, mySize.width, mySize.height);
    [self.view addSubview:departmentLb];
    
    UIButton *messageBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    UIImage *messageImage = [UIImage imageNamed:@"站内信"];
    messageBtn.frame = CGRectMake(900, departmentLb.frame.origin.y, messageImage.size.width, messageImage.size.height);
    [messageBtn setBackgroundImage:messageImage forState:UIControlStateNormal];
    [self.view addSubview:messageBtn];
    
    NSLog(@"%@",self.delegate.DataDic);
    UIImage *buttonImage = [UIImage imageNamed:@"选项按钮-底"];
    NSArray *imageNames = @[@"巡检",@"会议与接待",@"巡检记录查询",@"突发事件查询记录",@"报修记录查询",@"资料库",@"人员组织架构",@"公司信息",@"分析报告"];
    for (int i = 0; i<9; i++) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        button.frame = CGRectMake((1024-buttonImage.size.width*3)/4+((1024-buttonImage.size.width*3)/4 + buttonImage.size.width)*(i%3), 156+(30+buttonImage.size.height)*(i/3), buttonImage.size.width, buttonImage.size.height);
        [button setBackgroundImage:buttonImage forState:UIControlStateNormal];
        button.tag = i;
        [button addTarget:self action:@selector(clicked:) forControlEvents:UIControlEventTouchUpInside];
        [button addImage:[UIImage imageNamed:[imageNames objectAtIndex:i]] title:[imageNames objectAtIndex:i]];
        [self.view addSubview:button];
    }
    
    UIImage *blackImage = [UIImage imageNamed:@"黑底1"];
    blackView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, scrennWidth, screenHeight)];
    blackView.image = blackImage;
    blackView.userInteractionEnabled = YES;
    [self.view addSubview:blackView];
    UIImage *whiteImage = [UIImage imageNamed:@"小白白白底"];
    UIImageView *whiteView = [[UIImageView alloc]initWithImage:whiteImage];
    whiteView.frame = CGRectMake((scrennWidth - whiteImage.size.width)/2, (screenHeight - whiteImage.size.height)/2, whiteImage.size.width, whiteImage.size.height);
    [whiteView setUserInteractionEnabled:YES];
    [blackView addSubview:whiteView];
    
    UILabel *ziliaokuLB = [UILabel new];
    ziliaokuLB.text = @"资料库";
    ziliaokuLB.font = [UIFont systemFontOfSize:36];
    CGSize size = [ziliaokuLB.text sizeWithFont:ziliaokuLB.font constrainedToSize:CGSizeMake(MAXFLOAT, 40)];
    ziliaokuLB.frame = CGRectMake((whiteImage.size.width - size.width)/2, 75, size.width, size.height);
    [whiteView addSubview:ziliaokuLB];
    
    UIImage *btnImage = [UIImage imageNamed:@"资料库按钮"];
    UIImage *closeImage = [UIImage imageNamed:@"删除"];
    UIButton *clsBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [clsBtn setImage:closeImage forState:UIControlStateNormal];
    clsBtn.frame = CGRectMake(whiteImage.size.width - closeImage.size.width - 15, 15, closeImage.size.width, closeImage.size.height);
    [clsBtn addTarget:self action:@selector(closeV) forControlEvents:UIControlEventTouchUpInside];
    [whiteView addSubview:clsBtn];
    
    for (int i = 0 ; i < 2; i ++)
    {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        btn.frame = CGRectMake((whiteImage.size.width - btnImage.size.width*2)/3*(i+1)+(btnImage.size.width)*i, (whiteImage.size.height - ziliaokuLB.frame.size.height - ziliaokuLB.frame.origin.y)/2, btnImage.size.width, btnImage.size.height);
        btn.tag = i;
        UILabel *btnLb = [UILabel new];
        btnLb.font = [UIFont systemFontOfSize:36];
        if (btn.tag == 0) {
            btnLb.text = @"公司资料";
        }else{
            btnLb.text = @"部门资料";
        }
        btnLb.textColor = [UIColor whiteColor];
        size = [btnLb.text sizeWithFont:btnLb.font constrainedToSize:CGSizeMake(MAXFLOAT, 40)];
        btnLb.backgroundColor = [UIColor clearColor];
        btnLb.frame = CGRectMake((btnImage.size.width - size.width)/2, (btnImage.size.height - size.height)/2, size.width, size.height);
        [btn addSubview:btnLb];
        [btn setBackgroundColor:[UIColor clearColor]];
        [btn setBackgroundImage:btnImage forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(material:) forControlEvents:UIControlEventTouchUpInside];
        [whiteView addSubview:btn];
    }
    blackView.hidden = YES;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma - mark button action
- (void)clicked:(id)sender
{
    UIButton *button = (UIButton*)sender;
    switch (button.tag) {
        case 0:
        {
            switch ([[self.delegate.DataDic valueForKey:@"departmentid"]intValue]) {
#pragma mark - test
//            switch (self.delegate.testDepart){
                case 1:
                {
                    secureXJViewController *secure = [secureXJViewController new];
                    [self.navigationController pushViewController:secure animated:YES];                }
                    break;
                case 2:
                {
                    ProjectCJViewController *project = [ProjectCJViewController new];
                    [self.navigationController pushViewController:project animated:YES];
                }
                    break;
                case 3:
                {
                    FunctionXJViewController *function = [FunctionXJViewController new];
                    [self.navigationController pushViewController:function animated:YES];
                }
                    break;
                    
                default:
                    break;
            }
            
            
        }
            break;
        case 1:
        {
            MeetingViewController *meet = [[MeetingViewController alloc]initWithNibName:@"MeetingViewController" bundle:nil];
            [self.navigationController pushViewController:meet animated:YES];
        }
            break;
        case 2:
        {
            CheckViewController *check = [CheckViewController new];
            [self.navigationController pushViewController:check animated:YES];
        }
            break;
        case 3:
        {
            [Appinfomation shareIstance].strongXunJianCount = 0;
            EmergencyViewController *emergency = [EmergencyViewController new];
            [self.navigationController pushViewController:emergency animated:YES];
        }
            break;
        case 4:
        {
            BaoXiuJiLuViewController *baoxiu = [BaoXiuJiLuViewController new];
            [self.navigationController pushViewController:baoxiu animated:YES];
        }
            break;
        case 5:
        {
            blackView.hidden = NO;
            self.navigationController.navigationBar.hidden = YES;
        }
            break;
        case 6:
        {
            PerSonOrganizerViewController *person = [PerSonOrganizerViewController new];
            [self.navigationController pushViewController:person animated:YES];
        }
            break;
         case 7:
        {
            NewsViewController *newsView = [NewsViewController new];
            [self.navigationController pushViewController:newsView animated:YES];
        }
            break;
        default:
        {
            AnalysisViewController *anay = [AnalysisViewController new];
            [self.navigationController pushViewController:anay animated:YES];
        }
            break;
    }
}
- (void)material:(UIButton*)btn
{
    [self closeV];
    
    MaterialViewController *materialView = [MaterialViewController new];
    [self.navigationController pushViewController:materialView animated:YES];
    self.navigationController.navigationBar.hidden = NO;
}
- (void)closeV
{
    blackView.hidden = YES;
    self.navigationController.navigationBar.hidden = NO;
}
@end
